Repository navigation
perf(csr): bound the pattern-predicate walk at hubs and repeated nodes - #231
Merged
Merged
Conversation
PathExistsExec answers a pattern predicate per row by walking the CSR. Its last hop to a bound end walked the whole list of the node before it, so a hub there cost its degree per row: the shape suite's predicate grew 69x (memory) from hub degree 10 to 100,000 and ran 3.6x slower than the join path. With no memory of explored nodes, a longer predicate also paid the product of the degrees along every path. - The last hop to a bound end reads the shorter of its two ends' lists, as a closing edge does, when some source on that hop has a long list. - Each row remembers the nodes it has explored at each depth: any path from one ends the search, so a second visit can only fail again. One-hop predicates keep no memo.
7 of 16 tasks
Deploying lance-csr with
|
| Latest commit: |
f0e6fb4
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://16bd0f94.lance-csr.pages.dev |
| Branch Preview URL: | https://perf-pattern-predicate-walk.lance-csr.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #223.
Why
A pattern predicate such as
WHERE (b)-[:R]->()-[:P]->(a)asks, for each row, whether a path exists. With the CSR, the engine answers it by walking the graph fromb, one hop at a time, until it finds a path toa. That walk had two weak spots. On the last hop it scanned the full neighbour list of whatever node it had reached, so when that node was a hub with 100,000 neighbours, every row scanned all 100,000. And it kept no record of where it had already been, so a longer predicate could walk the same node again for every path that reached it, multiplying the degrees along the way.On
main, the shape suite's predicate through a hub got 72 times slower in memory mode (30 times in lazy mode) as the hub's degree rose from 10 to 100,000. At that degree it was 3.7 times slower than the same query withuse_csr=False.What changed
aabove), it checks the edge from whichever end has fewer neighbours, as a closing edge does since perf(csr): read a closing edge from its shorter end #228. The other end's list is the same edges keyed the other way, with the same edge rows. A hop whose sources all have at most 32 edges skips the comparison and scans, so low-degree predicates pay nothing for it.Validation
cargo test --workspace,cargo clippy --workspace --all-targets -- -D warnings,make test(1,814 passed), the strict docs build andtypospass locally. A new unit test walks a four-hop predicate in which two paths reach the same node before a hub hop, and checks that every end gives the same answer with and without the shorter-end read, that a missing end node matches nothing, and that the repeated node is explored once. CI has not run yet.CONTRIBUTING.md: release wheels frommain(5676cda) and this branch (f0e6fb4), alternatingmainand branch twice each,memoryandlazy. Every answer check and every shape-suite phrasing and plan check passed.Shape suite headlines (
smallgraph):Only the hub predicate queries moved by 15% or more: degree 1,000 by −35% (memory) and −23% (lazy), 10,000 by −89% and −77%, and 100,000 by −99% and −97%.
SF1 suites:
mainmainrun 2 / run 1IC7 and IC10 are the only suite queries with a pattern predicate. IC10 moved by −10% (memory) and −6% (lazy), which fits the change (its last hop now checks the bound end once instead of looking up every neighbour in the node index) but is within the noise range, so I don't claim it. IC7 didn't move, and no other SF1 query moved by 10% or more.
Machine: Apple M5 MacBook Pro, 24 GB, macOS 26.6.2. Load average 2.5 to 7.2, with the high end right after the release build.
Every SF1 query
graph-benchmark, memory
Geomean branch/main: 1.005; main run 2 / run 1: 0.997 (largest single-query main gap 1%)
graph-benchmark-ldbc, memory
Geomean branch/main: 0.994; main run 2 / run 1: 1.007 (largest single-query main gap 11%)
graph-benchmark-ldbc, lazy
Geomean branch/main: 0.996; main run 2 / run 1: 1.001 (largest single-query main gap 4%)
graph-benchmark-ldbc-complex, memory
Geomean branch/main: 0.997; main run 2 / run 1: 0.987 (largest single-query main gap 6%)
graph-benchmark-ldbc-complex, lazy
Geomean branch/main: 0.987; main run 2 / run 1: 1.006 (largest single-query main gap 4%)
Every shape-suite query
memory: small graph (20,000 accounts, 229,517 T edges, hub degrees [10, 1000, 10000, 100000])
Runs: main x2, branch x2.
main run-to-run geomean: 0.998; largest single-query gap 7%.
lazy: small graph (20,000 accounts, 229,517 T edges, hub degrees [10, 1000, 10000, 100000])
Runs: main x2, branch x2.
main run-to-run geomean: 0.998; largest single-query gap 7%.
🤖 Generated with Claude Code